<?php
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
///关于充值，提现统计，手续费
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and checktime>='$startdate' and  checktime<='$enddate'";  
}
$gfileds        = "SUBSTR(checktime,1,10 )";
if($MOD=="M"){
    $gfileds    = "SUBSTR(checktime,1,7)";    
} 
$rows = $dbselect->GetRows("select cid,$gfileds as checktime,
sum(if(aptype=4 and cs2='现金线下充值',money,0)) as 线下充值,sum(if(aptype=4,1,0)) as 线下充值次数,
sum(if(aptype=4 and cs2='现金线下充值' and fee>0,1,0)) as 线下充值手续费次,sum(if(aptype=4,fee,0)) as 线下充值手续费,
sum(if(aptype=5 and fee>0,1,0)) as 转可提手续费次,sum(if(aptype=5,fee,0)) as 转可提手续费,
sum(if(aptype=6,money,0)) as 提现,sum(if(aptype=6,1,0)) as 提现次数,
sum(if(aptype=6 and fee>0,1,0)) as 提现手续费次,sum(if(aptype=6,fee,0)) as 提现手续费,
sum(if(aptype=6 and fuid_isBorrower(uid)=1,money,0)) as 借提现,sum(if(aptype=6 and fuid_isBorrower(uid)=1,1,0)) as 借提现次数,
sum(if(aptype=6 and fuid_isBorrower(uid)=1 and fee>0,1,0)) as 借提现手续费次,sum(if(aptype=6 and fuid_isBorrower(uid)=1,fee,0)) as 借提现手续费,
sum(if(aptype=6 and fuid_isTender(uid)=1,money,0)) as 投提现,sum(if(aptype=6 and fuid_isTender(uid)=1,1,0)) as 投提现次数,
sum(if(aptype=6 and fuid_isTender(uid)=1 and fee>0,1,0)) as 投提现手续费次,sum(if(aptype=6 and fuid_isTender(uid)=1,fee,0)) as 投提现手续费,
sum(if(aptype=6 and fuid_isZhongJie(uid)=1,money,0)) as 中提现,sum(if(aptype=6 and fuid_isZhongJie(uid)=1,1,0)) as 中提现次数,
sum(if(aptype=6 and fuid_isZhongJie(uid)=1 and fee>0,1,0)) as 中提现手续费次,sum(if(aptype=6 and fuid_isZhongJie(uid)=1,fee,0)) as 中提现手续费,
sum(if(aptype=7 and csid2>0,money,0)) as 线上充值,sum(if(aptype=7 and csid2>0,1,0)) as 线上充值次数,
sum(if(aptype=7 and csid2>0 and fee>0,1,0)) as 线上充值手续费次,sum(if(aptype=7 and csid2>0,fee,0)) as 线上充值手续费,
sum(if(aptype=4 and cs2!='现金线下充值',money,0)) as 客服充值,sum(if(aptype=7 and csid2=0,1,0)) as 客服次数,
sum(if(aptype=4 and cs2!='现金线下充值' and fee>0,1,0)) as 客服手续费次,sum(if(aptype=7 and csid2=0,fee,0)) as 客服手续费,
sum(if(aptype=11,money,0)) as 代扣充值,sum(if(aptype=11,1,0)) as 代扣充值次数,
sum(if(aptype=11 and fee>0,1,0)) as 代扣手续费次,sum(if(aptype=11,fee,0)) as 代扣手续费
from 04a_3applyqueue where 
aptype in ( 4,6,7,11) and status=3 $sfwhere
group by cid,$gfileds");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = $row['checktime'];
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $c_c_xx = $row['线下充值次数'];
    $c_c_tx = $row['提现次数'];
    $c_c_zkt = $row['转可提手续费次'];
    $c_c_tx_b = $row['借提现次数'];
    $c_c_tx_t = $row['投提现次数'];
    $c_c_tx_z = $row['中提现次数'];
    $c_c_xs = $row['线上充值次数'];
    $c_c_kf = $row['客服次数'];
    $c_c_dk = $row['代扣充值次数']; 
    if($c_c_xx>0){
        CTLog::G()->pxxDayReal($c_c_xx.",cid",$cid,"线下充值",$row['线下充值'],$ctime);
        if($row['线下充值手续费']>0){
            CTLog::G()->pxxDayReal($row['线下充值手续费次'].",cid",$cid,"线下充值手续费",$row['线下充值手续费'],$ctime);
        }
    }
    if($c_c_zkt>0){
        CTLog::G()->pxxDayReal($row['转可提手续费次'].",cid",$cid,"转可提手续费",$row['转可提手续费'],$ctime);
    }
    if($c_c_tx>0){
        CTLog::G()->pxxDayReal($c_c_tx.",cid",$cid,"提现",$row['提现'],$ctime);
        if($row['提现手续费']>0){
            CTLog::G()->pxxDayReal($row['提现手续费次'].",cid",$cid,"提现手续费",$row['提现手续费'],$ctime);
        }
        if($c_c_tx_b>0){
            CTLog::G()->pxxDayReal($c_c_tx_b.",cid",$cid,"提现_借",$row['借提现'],$ctime);
            if($row['借提现手续费']>0){
                CTLog::G()->pxxDayReal($row['借提现手续费次'].",cid",$cid,"提现手续费_借",$row['借提现手续费'],$ctime);
            }
        }
        if($c_c_tx_t>0){
            CTLog::G()->pxxDayReal($c_c_tx_t.",cid",$cid,"提现_投",$row['投提现'],$ctime);
            if($row['投提现手续费']>0){
                CTLog::G()->pxxDayReal($row['投提现手续费次'].",cid",$cid,"提现手续费_投",$row['投提现手续费'],$ctime);
            }
        }
        if($c_c_tx_z>0){
            CTLog::G()->pxxDayReal($c_c_tx_z.",cid",$cid,"提现_中",$row['中提现'],$ctime);
            if($row['提现手续费']>0){
                CTLog::G()->pxxDayReal($row['中提现手续费次'].",cid",$cid,"提现手续费_中",$row['中提现手续费'],$ctime);
            }
        }
    }
    if($c_c_xs>0){
        CTLog::G()->pxxDayReal($c_c_xs.",cid",$cid,"线上充值",$row['线上充值'],$ctime);
        if($row['线上充值手续费']>0){
            CTLog::G()->pxxDayReal($row['线上充值手续费次'].",cid",$cid,"线上充值手续费",$row['线上充值手续费'],$ctime);
        }
    }
    if($c_c_kf>0){
        CTLog::G()->pxxDayReal($c_c_kf.",cid",$cid,"客服充值",$row['客服充值'],$ctime);
        if($row['客服手续费']>0){
            CTLog::G()->pxxDayReal($row['客服手续费次'].",cid",$cid,"客服充值手续费",$row['客服手续费'],$ctime);
        }
    }
    if($c_c_dk>0){
        CTLog::G()->pxxDayReal($c_c_dk.",cid",$cid,"代扣充值",$row['代扣充值'],$ctime);
        if($row['代扣手续费']>0){
            CTLog::G()->pxxDayReal($row['代扣手续费次'].",cid",$cid,"代扣充值手续费",$row['代扣手续费'],$ctime);
        }
    }
}


//APP线上充值
//安卓线上充值

$rows = $dbselect->GetRows("SELECT SUM(1) AS 安卓充值次数,SUM(money) AS 安卓充值金额, $gfileds as checktime FROM 04a_3applyqueue_7 
                            WHERE STATUS=3 $sfwhere AND cs2 LIKE '[App][android]%' group by cid");
foreach($rows as &$row){
    $ctime  = $row['checktime'];
    $cid    = $row['cid'];
    if($row['安卓充值次数']){
        CTLog::G()->pxxDayReal($row['安卓充值次数'].",cid",$cid,"安卓充值金额",$row['安卓充值金额'],$ctime);
    }
}
//苹果线上充值
$rows = $dbselect->GetRows("SELECT SUM(1) AS 苹果充值次数,SUM(money) AS 苹果充值金额, $gfileds as checktime FROM 04a_3applyqueue_7 
                            WHERE STATUS=3 $sfwhere AND cs2 LIKE '[App][IOS%' group by cid");
foreach($rows as &$row){
    $ctime  = $row['checktime'];
    $cid    = $row['cid'];
    if($row['苹果充值次数']){
        CTLog::G()->pxxDayReal($row['苹果充值次数'].",cid",$cid,"苹果充值金额",$row['苹果充值金额'],$row['times']);
    }
}

//总站
$rows = $dbselect->GetRows("select $gfileds as checktime,
sum(if(aptype=4,money,0)) as 线下充值,sum(if(aptype=4,1,0)) as 线下充值次数,
sum(if(aptype=4 and fee>0,1,0)) as 线下充值手续费次,sum(if(aptype=4,fee,0)) as 线下充值手续费,
sum(if(aptype=6,money,0)) as 提现,sum(if(aptype=6,1,0)) as 提现次数,
sum(if(aptype=6 and fee>0,1,0)) as 提现手续费次,sum(if(aptype=6,fee,0)) as 提现手续费,
sum(if(aptype=6 and fuid_isBorrower(uid)=1,money,0)) as 借提现,sum(if(aptype=6 and fuid_isBorrower(uid)=1,1,0)) as 借提现次数,
sum(if(aptype=6 and fuid_isBorrower(uid)=1 and fee>0,1,0)) as 借提现手续费次,sum(if(aptype=6 and fuid_isBorrower(uid)=1,fee,0)) as 借提现手续费,
sum(if(aptype=6 and fuid_isTender(uid)=1,money,0)) as 投提现,sum(if(aptype=6 and fuid_isTender(uid)=1,1,0)) as 投提现次数,
sum(if(aptype=6 and fuid_isTender(uid)=1 and fee>0,1,0)) as 投提现手续费次,sum(if(aptype=6 and fuid_isTender(uid)=1,fee,0)) as 投提现手续费,
sum(if(aptype=6 and fuid_isZhongJie(uid)=1,money,0)) as 中提现,sum(if(aptype=6 and fuid_isZhongJie(uid)=1,1,0)) as 中提现次数,
sum(if(aptype=6 and fuid_isZhongJie(uid)=1 and fee>0,1,0)) as 中提现手续费次,sum(if(aptype=6 and fuid_isZhongJie(uid)=1,fee,0)) as 中提现手续费,
sum(if(aptype=7 and csid2>0,money,0)) as 线上充值,sum(if(aptype=7 and csid2>0,1,0)) as 线上充值次数,
sum(if(aptype=7 and csid2>0 and fee>0,1,0)) as 线上充值手续费次,sum(if(aptype=7 and csid2>0,fee,0)) as 线上充值手续费,
sum(if(aptype=7 and csid2=0,money,0)) as 客服充值,sum(if(aptype=7 and csid2=0,1,0)) as 客服次数,
sum(if(aptype=7 and csid2=0 and fee>0,1,0)) as 客服手续费次,sum(if(aptype=7 and csid2=0,fee,0)) as 客服手续费,
sum(if(aptype=11,money,0)) as 代扣充值,sum(if(aptype=11,1,0)) as 代扣充值次数,
sum(if(aptype=11 and fee>0,1,0)) as 代扣手续费次,sum(if(aptype=11,fee,0)) as 代扣手续费
from 04a_3applyqueue where 
aptype in ( 4,6,7,11) and status=3 $sfwhere
group by $gfileds");
foreach($rows as &$row){
    $ctime  = $row['checktime'];
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $c_c_xx = $row['线下充值次数'];
    $c_c_tx = $row['提现次数'];
    $c_c_tx_b = $row['借提现次数'];
    $c_c_tx_t = $row['投提现次数'];
    $c_c_tx_z = $row['中提现次数'];
    $c_c_xs = $row['线上充值次数'];
    $c_c_kf = $row['客服次数'];
    $c_c_dk = $row['代扣充值次数']; 
    if($c_c_xx>0){
        CTLog::G()->pxxDayReal($c_c_xx.",sid",1,"线下充值",$row['线下充值'],$ctime);
        if($row['线下充值手续费']>0){
            CTLog::G()->pxxDayReal($row['线下充值手续费次'].",sid",1,"线下充值手续费",$row['线下充值手续费'],$ctime);
        }
    }
    if($c_c_tx>0){
        CTLog::G()->pxxDayReal($c_c_tx.",sid",1,"提现",$row['提现'],$ctime);
        if($row['提现手续费']>0){
            CTLog::G()->pxxDayReal($row['提现手续费次'].",sid",1,"提现手续费",$row['提现手续费'],$ctime);
        }
        if($c_c_tx_b>0){
            CTLog::G()->pxxDayReal($c_c_tx_b.",sid",1,"提现_借",$row['借提现'],$ctime);
            if($row['借提现手续费']>0){
                CTLog::G()->pxxDayReal($row['借提现手续费次'].",sid",1,"提现手续费_借",$row['借提现手续费'],$ctime);
            }
        }
        if($c_c_tx_t>0){
            CTLog::G()->pxxDayReal($c_c_tx_t.",sid",1,"提现_投",$row['投提现'],$ctime);
            if($row['投提现手续费']>0){
                CTLog::G()->pxxDayReal($row['投提现手续费次'].",sid",1,"提现手续费_投",$row['投提现手续费'],$ctime);
            }
        }
        if($c_c_tx_z>0){
            CTLog::G()->pxxDayReal($c_c_tx_z.",sid",1,"提现_中",$row['中提现'],$ctime);
            if($row['提现手续费']>0){
                CTLog::G()->pxxDayReal($row['中提现手续费次'].",sid",1,"提现手续费_中",$row['中提现手续费'],$ctime);
            }
        }
    }
    if($c_c_xs>0){
        CTLog::G()->pxxDayReal($c_c_xs.",sid",1,"线上充值",$row['线上充值'],$ctime);
        if($row['线上充值手续费']>0){
            CTLog::G()->pxxDayReal($row['线上充值手续费次'].",sid",1,"线上充值手续费",$row['线上充值手续费'],$ctime);
        }
    }
    if($c_c_kf>0){
        CTLog::G()->pxxDayReal($c_c_kf.",sid",1,"客服充值",$row['客服充值'],$ctime);
        if($row['客服手续费']>0){
            CTLog::G()->pxxDayReal($row['客服手续费次'].",sid",1,"客服充值手续费",$row['客服手续费'],$ctime);
        }
    }
    if($c_c_dk>0){
        CTLog::G()->pxxDayReal($c_c_dk.",sid",1,"代扣充值",$row['代扣充值'],$ctime);
        if($row['代扣手续费']>0){
            CTLog::G()->pxxDayReal($row['代扣手续费次'].",sid",1,"代扣充值手续费",$row['代扣手续费'],$ctime);
        }
    }
}



//APP线上充值
//安卓线上充值

$rows = $dbselect->GetRows("SELECT SUM(1) AS 安卓充值次数,SUM(money) AS 安卓充值金额, $gfileds as checktime FROM 04a_3applyqueue_7 WHERE STATUS=3 $sfwhere AND cs2 LIKE '[App][android]%'");
foreach($rows as &$row){
    $ctime  = $row['checktime'];
    if($row['安卓充值次数']){
        CTLog::G()->pxxDayReal($row['安卓充值次数'].",sid",1,"安卓充值金额",$row['安卓充值金额'],$ctime);
    }
}
//苹果线上充值
$rows = $dbselect->GetRows("SELECT SUM(1) AS 苹果充值次数,SUM(money) AS 苹果充值金额, $gfileds as checktime FROM 04a_3applyqueue_7 WHERE STATUS=3 $sfwhere AND cs2 LIKE '[App][IOS%'");
foreach($rows as &$row){
    $ctime  = $row['checktime'];
    if($row['苹果充值次数']){
        CTLog::G()->pxxDayReal($row['苹果充值次数'].",sid",1,"苹果充值金额",$row['苹果充值金额'],$ctime);
    }
}

